package thread;

import java.util.concurrent.CountDownLatch;

public class Demo44 {
    public static void main(String[] args) throws InterruptedException {
        // 可以判断各个线程（分工协作）是否已经完成一个共同的任务 类型与IDM
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(() -> {
                try {
                    System.out.println("beginning");
                    Thread.sleep(3000);
                    System.out.println("ending");
                    latch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            t.start();
        }
        latch.await();
        System.out.println("total ending");
    }
}
